package com.hdu.point_offer;

public class lcr181 {
    class Solution {
        // he sky is blue
        public String reverseMessage(String message) {
            StringBuilder ans = new StringBuilder();
            message = message.trim();
            int cur = message.length() - 1;
            while (cur >= 0)
            {
                int start = cur;
                while (cur >= 0 && message.charAt(cur) != ' ')
                {
                    cur--;
                }
                // [cur + 1, start] 是一个完整的单词
                ans.append(message.substring(cur + 1, start + 1)).append(" ");
                while (cur >= 0 && message.charAt(cur) == ' ')
                {
                    cur--;
                }
            }
            return ans.toString().trim();
        }
    }
}
